home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3125 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: stern.fokus.gmd.de!news
  2. From: Watson <sayegh@fokus.gmd.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: sizeof arrays in structs
  5. Date: Fri, 26 Jan 1996 10:59:48 +0100
  6. Organization: GMD FOKUS - Research Institute for Open Communication Systems
  7. Message-ID: <3108A614.A7F@fokus.gmd.de>
  8. References: <doc-150196151101@doc.farallon.com>
  9. NNTP-Posting-Host: pollux.fokus.gmd.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-2
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (X11; I; SunOS 5.4 sun4m)
  14.  
  15. eric doc kampman wrote:
  16. > typedef struct  {
  17. >         unsigned long   a[];
  18. >         size_t                  count;
  19. > }       CountArray;
  20.  
  21. This expression's already illegal (at least with C).
  22. An array must have a known size. 
  23.  
  24. > main()
  25. > {
  26. >                 size_t                  aSize, tSize;
  27. >         tSize = sizeof( tCArray );                                              // <--compiler is happy
  28. >         aSize = sizeof( aCArray.a );    // <--compiler says "illegal use of sizeof"
  29.  
  30. No size is no size is no size.
  31. You MUST use pointers if you don't know the size
  32. of an array.
  33. -- 
  34. *    Greetinx from Watson (sayegh@fokus.gmd.de)
  35.     http://www.fokus.gmd.de/ovma/employees/sayegh/entry.html
  36.     signal(SIGSEGV,SIG_IGN);
  37.